package redis.inaction.xx.utils;

public class ThreadLocalContext {

    private static final ThreadLocal<String> LOGIN_USER_ID_THREAD_LOCAL = new ThreadLocal<>();
    private static final ThreadLocal<String> C_CODE_THREAD_LOCAL = new ThreadLocal<>();
    private static final ThreadLocal<String> ACCESS_KEY_THREAD_LOCAL = new ThreadLocal<>();

    public static void setLoginUserId(String userId){
        LOGIN_USER_ID_THREAD_LOCAL.set(userId);
    }

    public static void setCode(String cityCode){
        C_CODE_THREAD_LOCAL.set(cityCode);
    }

    public static void setAccessKey(String accessKey){
        ACCESS_KEY_THREAD_LOCAL.set(accessKey);
    }

    public static String getLoginUserId(){
        return LOGIN_USER_ID_THREAD_LOCAL.get();
    }

    public static String getCode(){
        return C_CODE_THREAD_LOCAL.get();
    }

    public static String getAccessKey(){
        return ACCESS_KEY_THREAD_LOCAL.get();
    }

    public static void cleanContext() {
        LOGIN_USER_ID_THREAD_LOCAL.remove();
        C_CODE_THREAD_LOCAL.remove();
        ACCESS_KEY_THREAD_LOCAL.remove();
    }
}
